package com.xy.yunduo.web.interceptor;

import com.xy.yunduo.utils.annotion.AuthValidateAnnotion;
import com.xy.yunduo.utils.response.ApiException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor extends BaseInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        AuthValidateAnnotion authValidateAnnotion = getRequestAnnotation(handler,AuthValidateAnnotion.class);
//        if(authValidateAnnotion==null)
//            return true;
//        User user = (User)request.getSession().getAttribute("user");
//        if (user==null)
//            throw new ApiException(UserErrorCodes.NEED_LOGIN);
//        String role = authValidateAnnotion.role();
//        if(StringUtils.isBlank(role))
//            return false;
//        if(user.getRole().equals(RoleType.ADMIN.getCode())||user.getRole().equals(RoleType.ADMINISTRATOR.getCode()))
//            return true;
//        if(!role.contains(user.getRole()))
//            return false;
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
